home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
-
- #include "basedefs.h"
- #include "payroll.h"
-
- #define YIELDsc \
- {\
- int i;\
- MSG message;\
- for ( i = 0; i < 5; i++ )\
- while (PeekMessage (&message, 0, 0, 0, PM_REMOVE))\
- {\
- TranslateMessage(&message);\
- DispatchMessage(&message);\
- }\
- }
-
- WINPROC WndProc ( WINDOWS_PARAMS );
- DLGPROC PayrollDlgProc ( DIALOG_PARAMS );
-
- void RestoreSettings ( void );
- void SaveSettings ( void );
-
- void FillComboBoxes ( HWND hDlg, int iID, LPSTR szData );
- void ReArrangeCategoryData ( HWND hDlg, int iID, LPSTR szData );
- void MakeTransaction ( void );
-
- extern WORD FAR PASCAL WWWDDERun ( LPSTR, BOOL, LPSTR, HWND );
-
- extern void Add ( PMONEY Sum,
- MONEY Adder1,
- MONEY Adder2 );
-
- extern void Subtract ( PMONEY Difference,
- MONEY Subber1,
- MONEY Subber2 );
-
- extern BOOL bFigureDollarAmount ( LPSTR szIDD_AMOUNT, PMONEY pfAmount );
- extern int ItoA ( char *szString );
- extern int CentsItoA ( char *szString );
- extern LONG LtoA ( char *szString );
- extern void DollarsCents ( MONEY Cash, char *szBuckage, BYTE Flags );
-
-
- /**************************************************************
- * *
- * Global Variables *
- * *
- **************************************************************/
-
- //extern int __argc; // # of Command line parameters
- //extern char **__argv; // Command line parameter table
-
- HANDLE ghInst;
- HWND ghWnd;
- char szAppName[] = "PAYROLL";
- char szCaptionName[] = "Payroll Deposit";
- char szTopic[64]; // i.e. TUT
- int CentsPerDollar = 100;
- char cComma = ',';
- char cCurrency = '$';
- char cDecimal = '.';
- char szNullString[] = "";
- char szIniFileName[144];
-
-
- HANDLE hCommand;
- HANDLE hReturn;
-
- LPSTR szCommand;
- LPSTR szReturn;
-
- BOOL bRegister;
-
- typedef struct tagITEM
- {
- MONEY fAmount;
- char szCategory[66];
- }
- ITEM;
-
- ITEM Items[10];
-
- MONEY fNet;
- MONEY fGross;
- MONEY fGrossMinusNet;
-
-
- /**************************************************************
- * *
- * SanityCheck *
- * *
- **************************************************************/
- BOOL UserError ( void )
- {
- MessageBox ( NULL,
- "Payroll is a WinCheck Add-On Tool. "
- "Please run this tool from WinCheck. "
- "If this tool has not been installed "
- "from WinCheck, please select \"Add Tool...\""
- "from the WinCheck \"Tools\" menu.",
- "Payroll",
- MB_OK );
- return FALSE;
- }
-
- /**************************************************************
- * *
- * Intl *
- * *
- **************************************************************/
- void SetUpInternational ( void )
- {
- char szIni[2];
- int i;
-
- GetProfileString ( "intl", "sCurrency", szNullString, szIni, 2 );
- if (!(*szIni))
- cCurrency = '$';
- else
- cCurrency = *szIni;
-
- GetProfileString ( "intl", "sThousand", szNullString, szIni, 2 );
- if (!(*szIni))
- cComma = ',';
- else
- cComma = *szIni;
-
- GetProfileString ( "intl", "sDecimal", szNullString, szIni, 2 );
- if (!(*szIni))
- cDecimal = '.';
- else
- cDecimal = *szIni;
-
- i = GetProfileInt ( "intl", "iCurrDigits", 2 );
-
- if ( i > 4 ) i = 4;
-
- CentsPerDollar = 1;
- while ( i )
- {
- CentsPerDollar *= 10;
- i--;
- }
- }
-
- /**************************************************************
- * *
- * WinMain *
- * *
- **************************************************************/
-
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdLine, int nCmdShow )
- {
- MSG msg ;
- WNDCLASS wndclass ;
- int i;
-
-
- if (*lpszCmdLine != '/') return UserError();
-
- switch ( *(lpszCmdLine+1) )
- {
- case 'R': // Register WinCheck
-
- bRegister = TRUE;
- break;
-
- case 'L':
-
- bRegister = FALSE;
- break;
-
- default:
-
- return UserError();
- }
-
- // Set up the topic
-
- lstrcpy ( szTopic, lpszCmdLine+3 );
-
- GetModuleFileName ( hInstance, szIniFileName, 63 );
- i = lstrlen ( szIniFileName );
- while (szIniFileName[i] != '\\') i--;
- i++;
- szIniFileName[i] = 0; // Chop off PAYROLL.EXE
-
- lstrcat ( szIniFileName, "PAYROLL.INI" );
-
- i = 24;
-
- while ((!SetMessageQueue(i)) && (i >= 8)) i--;
-
- if (i < 8) return 0;
-
- SetUpInternational ( );
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = NULL;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = GetStockObject ( GRAY_BRUSH ) ;
- wndclass.lpszMenuName = (LPSTR)"PlainMenu" ;
- wndclass.lpszClassName = szAppName ;
-
- if (!RegisterClass (&wndclass))
- return FALSE;
- }
-
- ghInst = hInstance;
-
- hReturn = GlobalAlloc ( GHND, 65535L );
- hCommand = GlobalAlloc ( GHND, 65535L );
-
- if ((!hReturn) || (!hCommand)) return FALSE;
-
- szCommand = GlobalLock ( hCommand );
- szReturn = GlobalLock ( hReturn );
-
- RestoreSettings( );
-
- ghWnd = CreateWindow (szAppName, szCaptionName,
- WS_OVERLAPPEDWINDOW,
- 0, 0,
- 0, 0,
- NULL, NULL, hInstance, NULL) ;
-
- // No show window on the parent, instead bring up a dialog
-
- while (GetMessage((LPMSG)&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- GlobalUnlock ( hCommand );
- GlobalUnlock ( hReturn );
-
- GlobalFree ( hCommand );
- GlobalFree ( hReturn );
-
- return msg.wParam ;
- }
-
- /*********************************************************************
- * *
- * ModalDialog: Calls a Modal Dialog Box *
- * *
- *********************************************************************/
-
- int ModalDialog ( LPSTR TemplateName, FARPROC FunctionName, LONG dwParam )
- {
- FARPROC lpDialogProc;
- int RetVal;
-
- lpDialogProc = MakeProcInstance ( FunctionName, ghInst );
- RetVal = DialogBoxParam ( ghInst, TemplateName, ghWnd,
- lpDialogProc, (DWORD)dwParam );
- FreeProcInstance ( lpDialogProc );
- return RetVal;
- }
-
- /*********************************************************************
- * *
- * WndProc: Main Message Translator *
- * *
- *********************************************************************/
-
- WINPROC WndProc ( WINDOWS_PARAMS )
- {
- switch ( msg )
- {
- case WM_DESTROY :
-
- PostQuitMessage (0) ;
- break ;
-
- case WM_CREATE:
-
- PostMessage ( hWnd, WM_MYCOMMAND, IDM_MODAL, 0L );
- break;
-
- case WM_COMMAND :
- case WM_MYCOMMAND :
-
- switch ( wParam )
-
- {
- case IDM_MODAL :
-
- if (bRegister)
- {
- wsprintf (szCommand,
- "=e WinCheck %s "
- "[REGISTERADDON:"
- "e=\"Payroll\""
- ",d=\"%s...\""
- ",s=\"Make a Payroll Deposit\""
- ",c=\"%s\"]",
-
- (LPSTR)szTopic,
- (LPSTR)szCaptionName,
- (LPSTR)szCaptionName
- );
-
- WWWDDERun ( szCommand, 1, szReturn, ghWnd );
-
- YIELDsc
- }
-
- ModalDialog ( "PAYSTUB", PayrollDlgProc, 0L );
- PostMessage ( hWnd, WM_CLOSE, 0, 0L );
- break;
-
- default:
-
- return DefWindowProc ( hWnd, msg, wParam, lParam ) ;
- break;
- }
-
- break;
-
- default :
-
- return DefWindowProc ( hWnd, msg, wParam, lParam );
-
- }
- return 0L ;
- }
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void CalculateItems(HWND hDlg, int iRange, BOOL bCorrect)
- {
- int i, Start, Stop;
- char szText[128];
-
- if (-1 == iRange)
- {
- Start = 0; Stop = 10;
- }
- else
- {
- Start = iRange;
- Stop = iRange+1;
- }
-
- for ( i = Start; i < Stop; i++ )
- {
- GetDlgItemText ( hDlg, IDD_GROSS+i, szText, 127 );
- if (*szText)
- {
- bFigureDollarAmount( szText, &(Items[i].fAmount) );
- }
- else
- {
- Items[i].fAmount.Dollars = 0L;
- Items[i].fAmount.Cents = 0;
- }
-
- if (bCorrect)
- {
- DollarsCents ( Items[i].fAmount, szText, PLAIN );
- SetDlgItemText ( hDlg, IDD_GROSS+i, szText );
- }
-
- if (
- (Items[i].fAmount.Dollars) ||
- (Items[i].fAmount.Cents)
- )
- {
- int Index;
- BOOL bInviso;
-
- if (!IsWindowVisible (GetDlgItem ( hDlg, IDD_GROSS+i+100 )))
- {
- ShowWindow ( GetDlgItem ( hDlg, IDD_GROSS+i+100 ), SW_SHOW );
-
- Index = (int)SendDlgItemMessage(hDlg, IDD_GROSS+i+100, CB_GETCURSEL, 0, 0L);
- if (-1 == Index) Index = 0;
- SendDlgItemMessage(hDlg, IDD_GROSS+i+100, CB_GETLBTEXT, Index, (LONG)(LPSTR)szText);
- SetDlgItemText (hDlg, IDD_GROSS+i+100, szText );
- GetDlgItemText ( hDlg, IDD_GROSS+i+100, Items[i].szCategory, 65 );
- }
- else
- {
- GetDlgItemText ( hDlg, IDD_GROSS+i+100, Items[i].szCategory, 65 );
- }
- }
- else
- {
- ShowWindow ( GetDlgItem ( hDlg, IDD_GROSS+i+100 ), SW_HIDE );
- }
- }
-
- fNet.Dollars = fGross.Dollars = Items[0].fAmount.Dollars;
- fNet.Cents = fGross.Cents = Items[0].fAmount.Cents;
-
- for ( i = 1; i < 10; i++ )
- {
- Subtract ( &fNet, fNet, Items[i].fAmount );
- }
-
- DollarsCents ( fNet, szText, COMMAS | CURRENCY );
- SetDlgItemText ( hDlg, IDD_NETPAY, szText );
-
- Subtract ( &fGrossMinusNet, fGross, fNet );
-
- if (
- (Items[0].fAmount.Dollars) ||
- (Items[0].fAmount.Cents)
- )
- EnableWindow ( GetDlgItem ( hDlg, IDOK ), TRUE );
- else
- EnableWindow ( GetDlgItem ( hDlg, IDOK ), FALSE );
- }
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
-
- DLGPROC PayrollDlgProc ( DIALOG_PARAMS )
- {
- int i;
-
- switch (msg)
- {
- case WM_INITDIALOG:
-
- wsprintf (szCommand, "=r WinCheck %s Getcategories", (LPSTR)szTopic );
-
- WWWDDERun ( szCommand, TRUE, szReturn, ghWnd );
-
- PostMessage ( hDlg, WM_MYCOMMAND, IDD_REPAINT, 0L );
-
- SetWindowText (hDlg, szCaptionName);
-
- for ( i = IDD_C_GROSS; i <= IDD_C_OTHER5; i++)
- ShowWindow ( GetDlgItem ( hDlg, i ), SW_HIDE );
-
- return TRUE;
- break;
-
- case WM_COMMAND:
- case WM_MYCOMMAND:
-
- switch (wParam)
- {
- case IDD_GROSS :
- case IDD_FED :
- case IDD_STATE :
- case IDD_LOCAL :
- case IDD_FICA :
- case IDD_OTHER1:
- case IDD_OTHER2:
- case IDD_OTHER3:
- case IDD_OTHER4:
- case IDD_OTHER5:
-
- switch ( HIWORD (lParam))
- {
- case EN_KILLFOCUS:
-
- CalculateItems(hDlg, wParam - IDD_GROSS, TRUE);
- break;
-
- case EN_CHANGE:
-
- CalculateItems(hDlg, wParam - IDD_GROSS, FALSE);
- break;
- }
- break;
-
- case IDD_REPAINT:
-
- YIELDsc
- FillComboBoxes ( hDlg, IDD_C_GROSS , szReturn );
- ReArrangeCategoryData ( hDlg, IDD_C_GROSS , szReturn );
-
- FillComboBoxes ( hDlg, IDD_C_FED , szReturn );
- FillComboBoxes ( hDlg, IDD_C_STATE , szReturn );
- FillComboBoxes ( hDlg, IDD_C_LOCAL , szReturn );
- FillComboBoxes ( hDlg, IDD_C_FICA , szReturn );
- FillComboBoxes ( hDlg, IDD_C_OTHER1, szReturn );
- FillComboBoxes ( hDlg, IDD_C_OTHER2, szReturn );
- FillComboBoxes ( hDlg, IDD_C_OTHER3, szReturn );
- FillComboBoxes ( hDlg, IDD_C_OTHER4, szReturn );
- FillComboBoxes ( hDlg, IDD_C_OTHER5, szReturn );
-
- CalculateItems(hDlg, -1, TRUE);
-
- break;
-
- case IDOK:
-
- CalculateItems(hDlg, -1, TRUE);
- MakeTransaction ();
-
- break;
-
- case IDCANCEL:
-
- CalculateItems(hDlg, -1, TRUE);
- EndDialog(hDlg, TRUE);
- return (TRUE);
-
- case IDD_MEMORIZE:
-
- CalculateItems(hDlg, -1, TRUE);
- SaveSettings( );
- break;
-
- default:
- return FALSE;
-
- } // end WM_COMMAND wParam switch
- break;
-
- default:
- return FALSE;
- }
-
- return TRUE;
- }
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void RestoreSettings ( void )
- {
- char szTopic[10];
- char szReturn[81];
- int i;
-
- for ( i = 0; i < 10; i++ )
- {
- wsprintf ( szTopic, "L%d", i );
- GetPrivateProfileString ( szAppName, szTopic, "*", szReturn, 80, szIniFileName );
- if ('*' == *szReturn) // None found
- {
- Items[i].fAmount.Dollars = 0L;
- Items[i].fAmount.Cents = 0;
- Items[i].szCategory[0] = 0;
- }
- else // Item saved
- {
- lstrcpy (Items[i].szCategory, szReturn);
-
- wsprintf ( szTopic, "T%d", i );
- GetPrivateProfileString ( szAppName, szTopic, "0.00", szReturn, 80, szIniFileName );
- bFigureDollarAmount ( szReturn, &(Items[i].fAmount));
- }
- }
-
- }
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void SaveSettings ( void )
- {
- char szTopic[10];
- char szReturn[81];
- int i;
-
- for ( i = 0; i < 10; i++ )
- {
- if (
- (Items[i].fAmount.Dollars) ||
- (Items[i].fAmount.Cents)
- )
- {
- wsprintf ( szTopic, "T%d", i );
-
- DollarsCents ( Items[i].fAmount, szReturn, PLAIN );
-
- WritePrivateProfileString (szAppName, szTopic, szReturn, szIniFileName );
-
- lstrcpy (szReturn, Items[i].szCategory );
-
- wsprintf ( szTopic, "L%d", i );
-
- WritePrivateProfileString (szAppName, szTopic, szReturn, szIniFileName );
- }
- else // Delete from ini file
- {
- wsprintf ( szTopic, "L%d", i );
-
- WritePrivateProfileString (szAppName, szTopic, NULL, szIniFileName );
-
- wsprintf ( szTopic, "T%d", i );
-
- WritePrivateProfileString (szAppName, szTopic, NULL, szIniFileName );
- }
- }
-
- }
-
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void FillComboBoxes ( HWND hDlg, int iID, LPSTR szData )
- {
- int Start, Stop, i;
- char szNature[128];
-
- Start = 0;
- Stop = 0;
-
- while (szData[Start])
- {
- i = 0;
- do
- {
- szNature[i] = szData[Start];
- i++; Start++;
- }
- while (szData[Start] && (szData[Start] != 13));
- szNature[i] = 0;
- SendDlgItemMessage ( hDlg, iID, CB_ADDSTRING, 0, (LONG)(LPSTR)szNature );
- i = 0;
- if (szData[Start]) // Skip to next one
- Start += 2;
- }
-
- if (
- (Items[iID-IDD_GROSS-100].fAmount.Dollars) ||
- (Items[iID-IDD_GROSS-100].fAmount.Cents)
- )
- {
- i = (int)SendDlgItemMessage ( hDlg, iID, CB_FINDSTRING, -1,
- (LONG)(LPSTR)(Items[iID-IDD_GROSS-100].szCategory) );
-
- if ( -1 == i )
- i = SendDlgItemMessage ( hDlg, iID, CB_ADDSTRING, 0,
- (LONG)(LPSTR)(Items[iID-IDD_GROSS-100].szCategory) );
-
- if ( -1 == i )
- i = 0;
-
- DollarsCents ( Items[iID-IDD_GROSS-100].fAmount, szNature, PLAIN );
-
- SetDlgItemText ( hDlg, iID - 100, szNature );
-
- }
- else
- {
- i = 0;
- SetDlgItemText ( hDlg, iID - 100, "0.00" );
- }
-
- SendDlgItemMessage ( hDlg, iID, CB_SETCURSEL, i, 0L );
-
- }
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void ReArrangeCategoryData ( HWND hDlg, int iID, LPSTR szData )
- {
- int i, j;
- char szNature[128];
-
- i = (int)SendDlgItemMessage ( hDlg, iID, CB_GETCOUNT, 0, 0L );
- szData[0] = 0;
-
- for ( j = 0; j < i; j++ )
- {
- SendDlgItemMessage ( hDlg, iID, CB_GETLBTEXT, j, (LONG)(LPSTR)szNature );
- lstrcat ( szData, szNature );
- if (j != (i-1)) lstrcat ( szData, "\r\n" );
- }
-
- }
-
- /********************************************************************
- * *
- * *
- * *
- ********************************************************************/
-
- void MakeTransaction ( void )
- {
- char szMoney[32];
- char szItem[128];
- int i, Index;
-
- // Step 1: Make Net Transaction
-
- DollarsCents ( fNet, szMoney, PLAIN );
-
- wsprintf (szCommand,
- "=e WinCheck %s [CMISC:" /* Checking Misc */
- "CR" /* credit */
- ",DESC=\"Payroll Deposit\"" /* Description */
- ",T=\"%s\"" /* amount */
- ",L=\"%s\"]", /* Category */
- (LPSTR)szTopic,
- (LPSTR)szMoney,
- (LPSTR)Items[0].szCategory
- );
-
- WWWDDERun ( szCommand, TRUE, szReturn, ghWnd );
-
- YIELDsc
-
- // Step 2: Make Gross-Net Transaction
-
- DollarsCents ( fGrossMinusNet, szMoney, PLAIN );
-
- wsprintf (szCommand,
- "=e WinCheck %s [CMISC:" /* Checking Misc */
- "CR,C=X" /* credit, cleared */
- ",DESC=\"Payroll Gross-Net\"" /* Description */
- ",T=\"%s\"" /* amount */
- ",L=\"%s\"]", /* Category */
- (LPSTR)szTopic,
- (LPSTR)szMoney,
- (LPSTR)Items[0].szCategory
- );
-
- WWWDDERun ( szCommand, TRUE, szReturn, ghWnd );
-
- YIELDsc
-
- // Step 3: Make Deductions
-
- wsprintf (szCommand,
- "=e WinCheck %s [CMISC:" /* Checking Misc */
- "C=X" /* debit, cleared */
- ",T=\"%s\"" /* amount */
- ",DESC=\"Payroll Deductions\"", /* Description */
- (LPSTR)szTopic,
- (LPSTR)szMoney
- );
-
- Index = 0;
-
- for ( i = 1; i < 10; i++ )
- {
- if (
- (Items[i].fAmount.Dollars) ||
- (Items[i].fAmount.Cents)
- )
- {
- Index++;
-
- DollarsCents ( Items[i].fAmount, szMoney, PLAIN );
- wsprintf (szItem, ",$T=%d*%s,$L=%d*\"%s\"",
- Index,
- (LPSTR)szMoney,
- Index,
- (LPSTR)(Items[i].szCategory)
- );
- lstrcat ( szCommand, szItem );
- }
- }
-
- lstrcat ( szCommand, "]" );
-
- WWWDDERun ( szCommand, TRUE, szReturn, ghWnd );
-
- YIELDsc
-
-
-
- }